<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>指针实现例子</title>
</head>

<body>
    <script>
        class Range {
            constructor(start, end) {
                    this.start = start;
                    this.end = end;
                    this.next = null;
                }
                [Symbol.iterator]() {
                    let cur = this;

                    function next() {
                        if (cur) {
                            let tmp = [];
                            if (cur.start < cur.end) {
                                for (; ++cur.start < cur.end;) {
                                    tmp.push(cur.start);
                                }
                            }
                            cur = cur.next;
                            return {
                                value: tmp.join(',')
                            };
                        } else {
                            return {
                                done: true
                            };
                        }
                    }
                    return {
                        next
                    };
                }
        }

        let ra = new Range(1, 3);
        let rb = new Range(2, 8);
        let rc = new Range(5, 10);

        ra.next = rb;
        rb.next = rc;

        for (let x of ra) {
            // 分别打印出
            // 2
            // 3,4,5,6,7
            // 6,7,8,9
            console.log(x);
        }
    </script>
</body>

</html>